home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / src / test / test1.sml < prev    next >
Encoding:
Text File  |  1997-08-18  |  598 b   |  35 lines  |  [TEXT/R*ch]

  1. 1;
  2. 2 + ((fn 2 => 99 | x => x) 3);
  3.  
  4. let val x=99 in x+1 end;
  5.  
  6. val rec fact = fn 0 => 1 | n => n * fact(n-1);
  7. fact 4;
  8.  
  9. val rec append2 =
  10.   fn ([], ys) => ys
  11.    | (x::xs, ys) => x :: append2 (xs,ys)
  12. ;
  13. append2( [1,2,3], [4,5,6] );
  14.  
  15. val rec append =
  16.   fn xs => fn ys =>
  17.     case xs
  18.       of [] => ys
  19.        | x :: xs => x :: append xs ys
  20. ;
  21. append [1,2,3] [4,5,6];
  22.  
  23. val reverse = fn xs =>
  24.   let
  25.     val rec loop = fn ([],ys) => ys
  26.                     | (x::xs,ys) => loop (xs,x::ys)
  27.   in
  28.     loop (xs, []) end;
  29. reverse [1,2,3,4];
  30. reverse [true,false];
  31.  
  32. val op @ = append2;
  33. infixr 5 @;
  34. [1,2,3] @ [4,5,6];
  35.